<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/inet_stub/linklayer/contract/MACAddress.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00332.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">MACAddress.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2003 Andras Varga; CTIE, Monash University, Australia</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * This program is free software; you can redistribute it and/or</span>
<a name="l00005"></a>00005 <span class="comment"> * modify it under the terms of the GNU Lesser General Public License</span>
<a name="l00006"></a>00006 <span class="comment"> * as published by the Free Software Foundation; either version 2</span>
<a name="l00007"></a>00007 <span class="comment"> * of the License, or (at your option) any later version.</span>
<a name="l00008"></a>00008 <span class="comment"> *</span>
<a name="l00009"></a>00009 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00010"></a>00010 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00011"></a>00011 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00012"></a>00012 <span class="comment"> * GNU Lesser General Public License for more details.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * You should have received a copy of the GNU Lesser General Public License</span>
<a name="l00015"></a>00015 <span class="comment"> * along with this program; if not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<a name="l00016"></a>00016 <span class="comment">*/</span>
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#ifndef MACADDRESS_H_</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">#define MACADDRESS_H_</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;INETDefs.h&quot;</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#define MAC_ADDRESS_SIZE 6</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#define MAC_ADDRESS_MASK 0xffffffffffffL</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="keyword">class </span><a class="code" href="a00108.html">InterfaceToken</a>;
<a name="l00032"></a>00032 
<a name="l00036"></a><a class="code" href="a00130.html">00036</a> <span class="keyword">class </span>INET_API <a class="code" href="a00130.html">MACAddress</a>
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038   <span class="keyword">private</span>:
<a name="l00039"></a>00039     uint64 address;   <span class="comment">// 6*8=48 bit address, lowest 6 bytes are used, highest 2 bytes are always zero</span>
<a name="l00040"></a>00040     <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> autoAddressCtr; <span class="comment">// global counter for generateAutoAddress()</span>
<a name="l00041"></a>00041 
<a name="l00042"></a>00042   <span class="keyword">public</span>:
<a name="l00044"></a><a class="code" href="a00130.html#a9083fdb636ab09f77e7af806f2d471b6">00044</a>     <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a> <a class="code" href="a00130.html#a9083fdb636ab09f77e7af806f2d471b6">UNSPECIFIED_ADDRESS</a>;
<a name="l00045"></a>00045 
<a name="l00047"></a><a class="code" href="a00130.html#a64288e3935e32fec17884c040cf2d2e9">00047</a>     <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a> <a class="code" href="a00130.html#a64288e3935e32fec17884c040cf2d2e9">BROADCAST_ADDRESS</a>;
<a name="l00048"></a>00048 
<a name="l00050"></a><a class="code" href="a00130.html#ad7361315e8e61b3e5e1494c55cc4721f">00050</a>     <span class="keyword">static</span> <span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a> <a class="code" href="a00130.html#ad7361315e8e61b3e5e1494c55cc4721f">MULTICAST_PAUSE_ADDRESS</a>;
<a name="l00051"></a>00051 
<a name="l00055"></a><a class="code" href="a00130.html#a155b01d9d9c04fbe13ea9b821519b571">00055</a>     <a class="code" href="a00130.html#a155b01d9d9c04fbe13ea9b821519b571">MACAddress</a>() { address = 0; }
<a name="l00056"></a>00056 
<a name="l00060"></a><a class="code" href="a00130.html#acd5a34c4730c3ce448d9d727bb693827">00060</a>     <span class="keyword">explicit</span> <a class="code" href="a00130.html#acd5a34c4730c3ce448d9d727bb693827">MACAddress</a>(uint64 bits) { address = bits &amp; MAC_ADDRESS_MASK; }
<a name="l00061"></a>00061 
<a name="l00066"></a><a class="code" href="a00130.html#a46d88d3231c166f8f6305e181e62a02e">00066</a>     <span class="keyword">explicit</span> <a class="code" href="a00130.html#a46d88d3231c166f8f6305e181e62a02e">MACAddress</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *hexstr) { setAddress(hexstr); }
<a name="l00067"></a>00067 
<a name="l00071"></a><a class="code" href="a00130.html#a9ab1361f2773c6840f8fc96f73000b20">00071</a>     <a class="code" href="a00130.html#a9ab1361f2773c6840f8fc96f73000b20">MACAddress</a>(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other) { address = other.address; }
<a name="l00072"></a>00072 
<a name="l00076"></a><a class="code" href="a00130.html#a81e0e779bcc372284a137c141eb14f3d">00076</a>     <a class="code" href="a00130.html">MACAddress</a>&amp; <a class="code" href="a00130.html#a81e0e779bcc372284a137c141eb14f3d">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other) { address = other.address; <span class="keywordflow">return</span> *<span class="keyword">this</span>; }
<a name="l00077"></a>00077 
<a name="l00081"></a><a class="code" href="a00130.html#a5f94a6533e6b7854c43c0a562622156a">00081</a>     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="a00130.html#a5f94a6533e6b7854c43c0a562622156a">getAddressSize</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> MAC_ADDRESS_SIZE; }
<a name="l00082"></a>00082 
<a name="l00086"></a>00086     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> getAddressByte(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k) <span class="keyword">const</span>;
<a name="l00087"></a>00087 
<a name="l00091"></a>00091     <span class="keywordtype">void</span> setAddressByte(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> k, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> addrbyte);
<a name="l00092"></a>00092 
<a name="l00097"></a>00097     <span class="keywordtype">bool</span> tryParse(<span class="keyword">const</span> <span class="keywordtype">char</span> *hexstr);
<a name="l00098"></a>00098 
<a name="l00103"></a>00103     <span class="keywordtype">void</span> setAddress(<span class="keyword">const</span> <span class="keywordtype">char</span> *hexstr);
<a name="l00104"></a>00104 
<a name="l00108"></a>00108     <span class="keywordtype">void</span> getAddressBytes(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *addrbytes) <span class="keyword">const</span>;
<a name="l00109"></a>00109     <span class="keywordtype">void</span> getAddressBytes(<span class="keywordtype">char</span> *addrbytes)<span class="keyword"> const </span>{ getAddressBytes((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)addrbytes); }
<a name="l00110"></a>00110 
<a name="l00114"></a>00114     <span class="keywordtype">void</span> setAddressBytes(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *addrbytes);
<a name="l00115"></a>00115     <span class="keywordtype">void</span> setAddressBytes(<span class="keywordtype">char</span> *addrbytes) { setAddressBytes((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)addrbytes); }
<a name="l00116"></a>00116 
<a name="l00120"></a><a class="code" href="a00130.html#a38c4ea471051c76e593f2c6b0340b1fe">00120</a>     <span class="keywordtype">void</span> <a class="code" href="a00130.html#a38c4ea471051c76e593f2c6b0340b1fe">setBroadcast</a>() { address = MAC_ADDRESS_MASK; }
<a name="l00121"></a>00121 
<a name="l00125"></a><a class="code" href="a00130.html#aa65a288ef8fe0e08e66912ffda5e3706">00125</a>     <span class="keywordtype">bool</span> <a class="code" href="a00130.html#aa65a288ef8fe0e08e66912ffda5e3706">isBroadcast</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address == MAC_ADDRESS_MASK; }
<a name="l00126"></a>00126 
<a name="l00130"></a><a class="code" href="a00130.html#aec80ce7ee8f529716e4b9354e93ca3c0">00130</a>     <span class="keywordtype">bool</span> <a class="code" href="a00130.html#aec80ce7ee8f529716e4b9354e93ca3c0">isMulticast</a>()<span class="keyword"> const  </span>{ <span class="keywordflow">return</span> getAddressByte(0) &amp; 0x01; };
<a name="l00131"></a>00131 
<a name="l00135"></a><a class="code" href="a00130.html#ae41af013d782b46483e7d0c84f0ed107">00135</a>     <span class="keywordtype">bool</span> <a class="code" href="a00130.html#ae41af013d782b46483e7d0c84f0ed107">isUnspecified</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address == 0; }
<a name="l00136"></a>00136 
<a name="l00140"></a>00140     std::string str() <span class="keyword">const</span>;
<a name="l00141"></a>00141 
<a name="l00145"></a><a class="code" href="a00130.html#a79f00509111e457048de0d6f5ae7aede">00145</a>     uint64 <a class="code" href="a00130.html#a79f00509111e457048de0d6f5ae7aede">getInt</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address; }
<a name="l00146"></a>00146 
<a name="l00150"></a><a class="code" href="a00130.html#a2d1669ce517436105cd75faed677a303">00150</a>     <span class="keywordtype">bool</span> <a class="code" href="a00130.html#a2d1669ce517436105cd75faed677a303">equals</a>(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address == other.address; }
<a name="l00151"></a>00151 
<a name="l00155"></a><a class="code" href="a00130.html#af52a8fbbad1c1d4fa4c4c4689911698d">00155</a>     <span class="keywordtype">bool</span> <a class="code" href="a00130.html#af52a8fbbad1c1d4fa4c4c4689911698d">operator==</a>(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address == other.address; }
<a name="l00156"></a>00156 
<a name="l00160"></a><a class="code" href="a00130.html#a931bca85d72f853c0a5bda55edd85365">00160</a>     <span class="keywordtype">bool</span> <a class="code" href="a00130.html#a931bca85d72f853c0a5bda55edd85365">operator!=</a>(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address != other.address; }
<a name="l00161"></a>00161 
<a name="l00165"></a>00165     <span class="keywordtype">int</span> compareTo(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other) <span class="keyword">const</span>;
<a name="l00166"></a>00166 
<a name="l00171"></a>00171     <a class="code" href="a00108.html">InterfaceToken</a> formInterfaceIdentifier() <span class="keyword">const</span>;
<a name="l00172"></a>00172 
<a name="l00177"></a>00177     <span class="keyword">static</span> <a class="code" href="a00130.html">MACAddress</a> generateAutoAddress();
<a name="l00178"></a>00178 
<a name="l00179"></a>00179     <span class="keywordtype">bool</span> operator&lt;(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address &lt; other.address; }
<a name="l00180"></a>00180 
<a name="l00181"></a>00181     <span class="keywordtype">bool</span> operator&gt;(<span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> address &gt; other.address; }
<a name="l00182"></a>00182 };
<a name="l00183"></a>00183 
<a name="l00184"></a>00184 <span class="keyword">inline</span> std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, <span class="keyword">const</span> <a class="code" href="a00130.html">MACAddress</a>&amp; mac)
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186     <span class="keywordflow">return</span> os &lt;&lt; mac.<a class="code" href="a00130.html#a5eed6450abcdd795b2a3d59828a29802">str</a>();
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 
<a name="l00189"></a>00189 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>MACAddress.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
